/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ShowPictureDialog.java
 *

 */

package jmenu.gui;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.border.Border;
import jmenu.dbmodels.MGetImage;
import jmenu.main.Config;
import jmenu.main.Icons;

/**
 *
 * @author Roman
 */
public class ShowPictureDialog extends javax.swing.JDialog {

    private String title;
    private int pictureId;
    private MGetImage img;
    boolean isBig;

    /** Creates new form ShowPictureDialog */
    public ShowPictureDialog(java.awt.Frame parent, boolean modal)
    {
        super(parent, modal);
        initComponents();      
    }

    public void setImageIdAndText(int pictureId, String title)
    {
        this.pictureId = pictureId;
        this.title = title;
        this.img = Config.getKernel().queries.loadGetImageById(this.pictureId);
        this.setTitle(img.getName()+" - "+this.title);
        set300();
    }

    private void set300()
    {
        this.isBig = false;
        //this.setVisible(false);
        ImageIcon imgr = new ImageIcon(img.getImage().getImage().getScaledInstance(300, 300, Image.SCALE_SMOOTH));
        this.pictureLabel.setIcon(imgr);
        this.pictureLabel.setSize(300, 300);
        this.pictureLabel.setToolTipText("Pro zvětšení klikni");
        this.pictureLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.setSize(340, 355);
        this.setResizable(false);
        this.setLocationRelativeTo(getOwner());
        //this.setVisible(true);
    }

    private void set600()
    {
        this.isBig = true;
       // this.setVisible(false);
        ImageIcon imgr = new ImageIcon(img.getImage().getImage().getScaledInstance(600, 600, Image.SCALE_SMOOTH));
        this.pictureLabel.setIcon(imgr);
        this.pictureLabel.setSize(600, 600);
        this.pictureLabel.setToolTipText("Pro zmenšení klikni");
        this.pictureLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.setSize(640, 655);
        this.setResizable(false);
        this.setLocationRelativeTo(getOwner());
       // this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pictureLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setBackground(java.awt.Color.white);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setForeground(new java.awt.Color(255, 255, 255));

        pictureLabel.setBackground(new java.awt.Color(255, 255, 255));
        pictureLabel.setForeground(new java.awt.Color(255, 255, 255));
        pictureLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        pictureLabel.setAlignmentY(0.0F);
        pictureLabel.setName("pictureLabel"); // NOI18N
        pictureLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pictureLabelMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pictureLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pictureLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void pictureLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pictureLabelMouseClicked

        if (isBig)
            set300();
        else
            set600();
}//GEN-LAST:event_pictureLabelMouseClicked



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel pictureLabel;
    // End of variables declaration//GEN-END:variables

}
